﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

namespace WEEK09_上课演示
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }

        private void ShowData()
        {
            string connectionString = "data source=10.22.149.99;database=School;uid=Student;pwd=123456";
            var connection = new SqlConnection(connectionString);
            string commandText = "SELECT * FROM Student";

            var dataAdapter = new SqlDataAdapter(commandText, connection);
            //SqlDataAdapter dataAdapter=new SqlDataAdapter(commandText,connectionString);

            //SqlCommand selectCommand = new SqlCommand(commandText, connection);
            //dataAdapter.SelectCommand = selectCommand;

            var dataSet = new DataSet();
            dataAdapter.Fill(dataSet, "Student");

            //DataTable dataTable = new DataTable();

            //dataAdapter.Fill(dataTable);

            // dataAdapter.SelectCommand.CommandText = "SELECT * FROM Course";
            //dataAdapter.Fill(dataSet, "Course");

            GridView1.DataSource = dataSet;
            GridView1.DataBind();
        }
    }
}